home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / desktop / np20.zip / NEWPAPER.C next >
C/C++ Source or Header  |  1992-06-01  |  3KB  |  130 lines

  1.  
  2.  
  3.  
  4. // ***********************************************************************
  5. //   NEWPAPER.C
  6. //
  7. //   Synopsis:
  8. //      Updates WIN.INI Wallpaper specification to point to the next BMP
  9. //      file in the specified subdirectory.
  10. //
  11. //   Environment:
  12. //      Borland C++ for Windows version 3.0 used to compile program.
  13. //      LARGE memory model - tab size 4
  14. //
  15. //   History:
  16. //      07/28/90    Jim Button    Original creation.
  17. //      06/01/92    Bob Jack      Cleaned up and modified code to compile
  18. //                                using Borland's C++. Added user defined
  19. //                                subdirectory for *.BMPs.
  20. // ***********************************************************************
  21. //
  22. //   Instalation:
  23. //
  24. //   Use the NOTEPAD function in Windows to add this to your WIN.INI file
  25. //   (WIN.INI is in your windows directory):
  26. //
  27. //      Under [windows] add or change to:
  28. //         run=newpaper.exe       This runs newpaper.exe on startup.
  29. //
  30. //   Optional - For user defined *.BMP storage:
  31. //
  32. //      Under [Desktop] add or change to:
  33. //         bmpdir=d:\bitmaps      Change "d:\bitmaps" to whatever drive/dir
  34. //                                your bitmaps (*.BMP) are stored in.
  35. // ***********************************************************************
  36.  
  37. #include    <windows.h>
  38. #include    <sys/types.h>
  39. #include    <sys/stat.h>
  40. #include    <dos.h>
  41. #include    <string.h>
  42.  
  43. #define        MAX_PROF_STR    81
  44.  
  45. // ***********************************************************************
  46.  
  47. #pragma argsused
  48.  
  49. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  50.     LPSTR lpCmdLine, int nCmdShow)
  51.     {
  52.     struct    ffblk    ff;
  53.     struct    stat    buf;
  54.     int        x, done;
  55.     char    WallPaper []            = "Wallpaper",
  56.             bmpdir [MAX_PROF_STR]   = "",
  57.             npsubdir [MAX_PROF_STR] = "",
  58.             curfile [MAX_PROF_STR]  = "",
  59.             newfile [MAX_PROF_STR]  = "",
  60.             *tiled;
  61.     char    drv [3], dir [66], nam [13], ext [5];
  62.  
  63.     // Check for valid bmpdir subdirectory
  64.  
  65.     GetProfileString ("Desktop", "bmpdir", "", bmpdir, MAX_PROF_STR - 1);
  66.     if (strlen (bmpdir) > 0)
  67.         {
  68.         strcpy (npsubdir, bmpdir);
  69.         strupr (npsubdir);
  70.         x = strlen (npsubdir) - 1;
  71.         if (npsubdir [x] == '\\')
  72.             npsubdir [x] = 0;
  73.         if (access (npsubdir, 0) != 0)            // If can't find dir,
  74.             npsubdir [0] = '\0';                // use default dir
  75.         else
  76.             strcat (npsubdir, "\\");
  77.         }
  78.  
  79.     //   Get old *.BMP file name
  80.  
  81.     GetProfileString ("Desktop", WallPaper, "", curfile, MAX_PROF_STR - 1);
  82.     fnsplit (curfile, drv, dir, nam, ext);
  83.     strcat (nam, ext);
  84.  
  85.     //   Find first *.BMP in subdir
  86.  
  87.     sprintf (curfile, "%s%s", npsubdir, "*.BMP");
  88.     done = findfirst (curfile, &ff, 0);
  89.     if (!done)
  90.         {
  91.         sprintf (newfile, "%s%s", npsubdir, ff.ff_name);
  92.         }
  93.  
  94.     // Find next *.BMP in subdir
  95.  
  96.     while (!done)
  97.         {
  98.         if (!strcmpi (ff.ff_name, nam))
  99.             {
  100.             done = findnext (&ff);
  101.             if (!done)
  102.                 sprintf (newfile, "%s%s", npsubdir, ff.ff_name);
  103.             break;
  104.             }
  105.         done = findnext (&ff);
  106.         }
  107.  
  108.     // Save to WIN.INI file
  109.  
  110.     WriteProfileString ("Desktop", WallPaper, newfile);
  111.  
  112.     // Tile Wallpaper if BMP is under 100k
  113.  
  114.     if (stat (newfile, &buf) != -1)
  115.         {
  116.         if (buf.st_size < 100000L)            tiled = "1";
  117.         else                                tiled = "0";
  118.         }
  119.     WriteProfileString ("Desktop", "TileWallpaper", tiled);
  120.  
  121.     // End program - remove from memory
  122.  
  123.     return (FALSE);
  124.     }
  125.  
  126. // ***********************************************************************
  127.  
  128.  
  129.  
  130.